package com.d.ui.view.tick;

import com.d.lib.ui.view.tick.CTickView;
import com.d.lib.ui.view.tick.STickView;
import com.d.ui.view.ResourceTable;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.app.Context;

/**
 * CTickView Test
 * Created by D on 2017/4/20.
 */
public class CTickViewLayout extends DirectionalLayout implements Component.ClickedListener {

  private CTickView cTickView;
  private STickView sTickView;

  public CTickViewLayout(Context context) {
    super(context);
    init(context);
  }

  public CTickViewLayout(Context context, AttrSet attrs) {
    super(context, attrs);
    init(context);
  }

  public CTickViewLayout(Context context, AttrSet attrs, int defStyleAttr) {
    super(context, attrs, String.valueOf(defStyleAttr));
    init(context);
  }


  public void init(Context context) {
    Component view = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_layout_ctick,
        this, true);
    cTickView = (CTickView) view.findComponentById(ResourceTable.Id_ctv_tick);
    sTickView = (STickView) view.findComponentById(ResourceTable.Id_stv_tick);
    view.findComponentById(ResourceTable.Id_btn_ctv_start).setClickedListener(this);
    view.findComponentById(ResourceTable.Id_btn_ctv_stop).setClickedListener(this);
  }

  @Override
  public void onClick(Component component) {
    int resId = component.getId();
    if (resId == ResourceTable.Id_btn_ctv_start) {
      cTickView.start();
      sTickView.start();
    } else if (resId == ResourceTable.Id_btn_ctv_stop) {
      cTickView.stop();
      sTickView.stop();
    }
  }
}
